package com.algorithm.one2fifty;

/**
 * @author tuzhijin
 */
public class Palindrome_9 {
    public static void main(String[] args) {
        System.out.println(isPalindrome(12321));
    }

    public static Boolean isPalindrome(int x) {
        int reserve = 0;
        // 负数和个位位0的不可能是回文数
        if (x < 0 || (x != 0 && x % 10 == 0)) {
            return false;
        }
        // 翻转后的数字大于原数字就退出循环
        while (x > reserve) {
            reserve = reserve * 10 + x % 10;
            x = x / 10;
        }
        return reserve == x || x == reserve / 10;
    }
}
